﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace BrainTechLLC.Silverlight.ClientApplication
{
    public partial class TypeFilter : UserControl
    {
        public event EventHandler<ObjectEventArgs<Type>> SelectedTypeChanged;

        public static readonly DependencyProperty TypesProperty = DependencyProperty.Register(
            "Types", typeof(ObservableCollection<Type>), typeof(TypeFilter),
            new PropertyMetadata(null, new PropertyChangedCallback(TypesChanged)));

        public ObservableCollection<Type> Types
        {
            get { return (ObservableCollection<Type>)GetValue(TypesProperty); }
            set { SetValue(TypesProperty, value); }
        }

        private static void TypesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TypeFilter t = (TypeFilter)d;
            t.Types = e.NewValue as ObservableCollection<Type>;
            t.SetTypeData();
        }

        public void SetTypeData()
        {
            cboTypes.ItemsSource = Types;
        }

        public Type CurrentSelectedType
        {
            get
            {
                if (cboTypes == null)
                    return null;

                return cboTypes.SelectedItem as Type;
            }
        }

        public TypeFilter()
        {
            InitializeComponent();
        }

        private void cboTypes_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Type t = Types[cboTypes.SelectedIndex];

            if (SelectedTypeChanged != null)
                SelectedTypeChanged(this, new ObjectEventArgs<Type>(t));
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            ObservableCollection<Type> types = new ObservableCollection<Type>();
            types.Add(null);
            types.Add(typeof(GameChar));
            types.Add(typeof(Channel));
            types.Add(typeof(GameCharTemplate));
            types.Add(typeof(GameThingBaseClass));
            types.Add(typeof(GameLocation));
            types.Add(typeof(Template));
            types.Add(typeof(Media));
            types.Add(typeof(CommandToPerform));
            types.Add(typeof(Ability));
            types.Add(typeof(State));
            types.Add(typeof(StateTemplate));
            types.Add(typeof(Item));
            types.Add(typeof(Area));
            types.Add(typeof(Reset));
            types.Add(typeof(LocationEdge));
            types.Add(typeof(LocationEdgeData));
            types.Add(typeof(ItemTemplate));
            types.Add(typeof(SingleInfluence));
            Types = types;
        }
    }
}
